package com.example.demo.service.impl;

import com.example.demo.dao.*;
import com.example.demo.mapper.GoodsMapper;
import com.example.demo.mapper.ImagePathMapper;
import com.example.demo.mapper.ShopcartMapper;
import com.example.demo.service.ShopCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShopCartServiceImpl implements ShopCartService {
    @Autowired
    private ShopcartMapper shopcartMapper;
    @Autowired
    private GoodsMapper goodsMapper;
    @Autowired
    private ImagePathMapper imagePathMapper;

    //添加商品进购物车
    @Override
    public int addshopcar(Shopcart shopcart) {
        return shopcartMapper.insert(shopcart);
    }

    //查看购物车
    @Override
    public List<Shopcart> searchShopcar(Integer id) {
        ShopcartExample shopcartExample = new ShopcartExample();
        ShopcartExample.Criteria criteria = shopcartExample.createCriteria();
        criteria.andUseridEqualTo(id);
       List<Shopcart> shopcarts= shopcartMapper.selectByExample(shopcartExample);
//       for(Shopcart shopcart :shopcarts){
//           GoodsExample goodsExample = new GoodsExample();
//           GoodsExample.Criteria criteria1 = goodsExample.createCriteria();
//           criteria1.andGoodsidEqualTo(shopcart.getGoodsid());
//          List<Goods> goods=  goodsMapper.selectByExample(goodsExample);
//          for(Goods goods1 :goods){
//              ImagePathExample imagePathExample = new ImagePathExample();
//              ImagePathExample.Criteria criteria2 = imagePathExample.createCriteria();
//              criteria2.andGoodidEqualTo(goods1.getGoodsid());
//              goods1.setImagePaths(imagePathMapper.selectByExample(imagePathExample));
//          }
//          shopcart.setGoods(goods);
//       }
        return shopcarts;
    }
}
